<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Vim常用命令 | whoway</title>
    <meta name="description" content="Personal Blog Website">
    <link rel="icon" href="/images/photo.jpg">
  <link rel="manifest" href="/images/photo.jpg">
  <link rel="apple-touch-icon" href="/images/photo.jpg">
  <meta http-quiv="pragma" cotent="no-cache">
  <meta http-quiv="pragma" cotent="no-cache,must-revalidate">
  <meta http-quiv="expires" cotent="0">
    
    <link rel="preload" href="/assets/css/0.styles.0dbae9ec.css" as="style"><link rel="preload" href="/assets/js/app.c70e21ad.js" as="script"><link rel="preload" href="/assets/js/108.a2fecadc.js" as="script"><link rel="prefetch" href="/assets/js/10.15222a53.js"><link rel="prefetch" href="/assets/js/100.7e0e5a86.js"><link rel="prefetch" href="/assets/js/101.efd59f25.js"><link rel="prefetch" href="/assets/js/102.dfbdc06c.js"><link rel="prefetch" href="/assets/js/103.d3ab2109.js"><link rel="prefetch" href="/assets/js/104.117957ef.js"><link rel="prefetch" href="/assets/js/105.046e8ff3.js"><link rel="prefetch" href="/assets/js/106.aebdc17d.js"><link rel="prefetch" href="/assets/js/107.248733c2.js"><link rel="prefetch" href="/assets/js/109.35196857.js"><link rel="prefetch" href="/assets/js/11.770642f2.js"><link rel="prefetch" href="/assets/js/110.cf3d973c.js"><link rel="prefetch" href="/assets/js/111.f985889a.js"><link rel="prefetch" href="/assets/js/112.ad614f41.js"><link rel="prefetch" href="/assets/js/113.f666653c.js"><link rel="prefetch" href="/assets/js/114.c6c3f384.js"><link rel="prefetch" href="/assets/js/115.e51d3c2f.js"><link rel="prefetch" href="/assets/js/116.4f4b39f5.js"><link rel="prefetch" href="/assets/js/117.99352e11.js"><link rel="prefetch" href="/assets/js/118.c6ae6572.js"><link rel="prefetch" href="/assets/js/119.4ccbe778.js"><link rel="prefetch" href="/assets/js/12.042a92ff.js"><link rel="prefetch" href="/assets/js/120.edda1c4f.js"><link rel="prefetch" href="/assets/js/121.30a638ed.js"><link rel="prefetch" href="/assets/js/122.6efcefb1.js"><link rel="prefetch" href="/assets/js/123.91e6665b.js"><link rel="prefetch" href="/assets/js/124.f27e3d7e.js"><link rel="prefetch" href="/assets/js/125.c75712d5.js"><link rel="prefetch" href="/assets/js/126.ed756cce.js"><link rel="prefetch" href="/assets/js/127.2f06c74c.js"><link rel="prefetch" href="/assets/js/128.d5f6f30e.js"><link rel="prefetch" href="/assets/js/129.508b7eed.js"><link rel="prefetch" href="/assets/js/13.b5280c37.js"><link rel="prefetch" href="/assets/js/130.dc05f9aa.js"><link rel="prefetch" href="/assets/js/131.e0ba69b1.js"><link rel="prefetch" href="/assets/js/132.d79bcaa4.js"><link rel="prefetch" href="/assets/js/133.34acc01a.js"><link rel="prefetch" href="/assets/js/134.dabf64d5.js"><link rel="prefetch" href="/assets/js/135.ad90c915.js"><link rel="prefetch" href="/assets/js/136.dbb0074f.js"><link rel="prefetch" href="/assets/js/137.284ad365.js"><link rel="prefetch" href="/assets/js/138.a4b6856f.js"><link rel="prefetch" href="/assets/js/139.c9c1e20f.js"><link rel="prefetch" href="/assets/js/14.df02ba38.js"><link rel="prefetch" href="/assets/js/140.8b0a9269.js"><link rel="prefetch" href="/assets/js/141.9c7759c5.js"><link rel="prefetch" href="/assets/js/142.a4201a82.js"><link rel="prefetch" href="/assets/js/143.d7da6e8c.js"><link rel="prefetch" href="/assets/js/144.5e48e65d.js"><link rel="prefetch" href="/assets/js/145.a0e2633c.js"><link rel="prefetch" href="/assets/js/146.3c775f9b.js"><link rel="prefetch" href="/assets/js/147.22add89a.js"><link rel="prefetch" href="/assets/js/148.cfde1009.js"><link rel="prefetch" href="/assets/js/149.ffc835b5.js"><link rel="prefetch" href="/assets/js/15.fbdfc4ee.js"><link rel="prefetch" href="/assets/js/150.406c4b20.js"><link rel="prefetch" href="/assets/js/151.b2040eea.js"><link rel="prefetch" href="/assets/js/152.7bc65661.js"><link rel="prefetch" href="/assets/js/153.1d7c65e3.js"><link rel="prefetch" href="/assets/js/154.1309de49.js"><link rel="prefetch" href="/assets/js/155.81d3ee1f.js"><link rel="prefetch" href="/assets/js/156.154a4ef2.js"><link rel="prefetch" href="/assets/js/16.e5eb6147.js"><link rel="prefetch" href="/assets/js/17.57853c4a.js"><link rel="prefetch" href="/assets/js/18.cb9d7518.js"><link rel="prefetch" href="/assets/js/19.f354dc47.js"><link rel="prefetch" href="/assets/js/2.570d8a23.js"><link rel="prefetch" href="/assets/js/20.b5af7fad.js"><link rel="prefetch" href="/assets/js/21.0b1928fe.js"><link rel="prefetch" href="/assets/js/22.f78666de.js"><link rel="prefetch" href="/assets/js/23.29c3f366.js"><link rel="prefetch" href="/assets/js/24.6f596516.js"><link rel="prefetch" href="/assets/js/25.14067b60.js"><link rel="prefetch" href="/assets/js/26.74ba4989.js"><link rel="prefetch" href="/assets/js/27.13d60edd.js"><link rel="prefetch" href="/assets/js/28.9523cb32.js"><link rel="prefetch" href="/assets/js/29.8ec842e9.js"><link rel="prefetch" href="/assets/js/3.3fb3d2e0.js"><link rel="prefetch" href="/assets/js/30.805597a8.js"><link rel="prefetch" href="/assets/js/31.831b195d.js"><link rel="prefetch" href="/assets/js/32.063c672d.js"><link rel="prefetch" href="/assets/js/33.6d93fac3.js"><link rel="prefetch" href="/assets/js/34.56e8263c.js"><link rel="prefetch" href="/assets/js/35.dbe688bb.js"><link rel="prefetch" href="/assets/js/36.dc5af2c1.js"><link rel="prefetch" href="/assets/js/37.0a7494f6.js"><link rel="prefetch" href="/assets/js/38.fe4fc171.js"><link rel="prefetch" href="/assets/js/39.f5ed5e92.js"><link rel="prefetch" href="/assets/js/4.2c405ec8.js"><link rel="prefetch" href="/assets/js/40.fe7e2714.js"><link rel="prefetch" href="/assets/js/41.30b0811d.js"><link rel="prefetch" href="/assets/js/42.76f52d62.js"><link rel="prefetch" href="/assets/js/43.e7bb0817.js"><link rel="prefetch" href="/assets/js/44.ead0e883.js"><link rel="prefetch" href="/assets/js/45.235df046.js"><link rel="prefetch" href="/assets/js/46.5f09e829.js"><link rel="prefetch" href="/assets/js/47.67116354.js"><link rel="prefetch" href="/assets/js/48.31f34543.js"><link rel="prefetch" href="/assets/js/49.10b5ebba.js"><link rel="prefetch" href="/assets/js/5.6f47322c.js"><link rel="prefetch" href="/assets/js/50.c0f0b7f1.js"><link rel="prefetch" href="/assets/js/51.5143f3bf.js"><link rel="prefetch" href="/assets/js/52.eeddfd48.js"><link rel="prefetch" href="/assets/js/53.eb790db5.js"><link rel="prefetch" href="/assets/js/54.8fe5421c.js"><link rel="prefetch" href="/assets/js/55.d8f9004b.js"><link rel="prefetch" href="/assets/js/56.62ac9b92.js"><link rel="prefetch" href="/assets/js/57.a9caec0d.js"><link rel="prefetch" href="/assets/js/58.f93fc522.js"><link rel="prefetch" href="/assets/js/59.a81a03aa.js"><link rel="prefetch" href="/assets/js/6.8c2ea393.js"><link rel="prefetch" href="/assets/js/60.ab782775.js"><link rel="prefetch" href="/assets/js/61.6dd12daf.js"><link rel="prefetch" href="/assets/js/62.76f4b01f.js"><link rel="prefetch" href="/assets/js/63.6f8a4742.js"><link rel="prefetch" href="/assets/js/64.6f8bb1fa.js"><link rel="prefetch" href="/assets/js/65.4120a44b.js"><link rel="prefetch" href="/assets/js/66.360c2d2b.js"><link rel="prefetch" href="/assets/js/67.26f84d32.js"><link rel="prefetch" href="/assets/js/68.68f45e5e.js"><link rel="prefetch" href="/assets/js/69.e311eb56.js"><link rel="prefetch" href="/assets/js/7.6762b2d7.js"><link rel="prefetch" href="/assets/js/70.cea82674.js"><link rel="prefetch" href="/assets/js/71.783ddcf7.js"><link rel="prefetch" href="/assets/js/72.e5467385.js"><link rel="prefetch" href="/assets/js/73.b8fb681b.js"><link rel="prefetch" href="/assets/js/74.1bae37db.js"><link rel="prefetch" href="/assets/js/75.024387e5.js"><link rel="prefetch" href="/assets/js/76.a8e53010.js"><link rel="prefetch" href="/assets/js/77.8c55500a.js"><link rel="prefetch" href="/assets/js/78.7ce90bf5.js"><link rel="prefetch" href="/assets/js/79.ef71713f.js"><link rel="prefetch" href="/assets/js/8.788a6364.js"><link rel="prefetch" href="/assets/js/80.acad589d.js"><link rel="prefetch" href="/assets/js/81.02670d10.js"><link rel="prefetch" href="/assets/js/82.53b7b1ac.js"><link rel="prefetch" href="/assets/js/83.99eb8581.js"><link rel="prefetch" href="/assets/js/84.d1535ce3.js"><link rel="prefetch" href="/assets/js/85.fe2b7de9.js"><link rel="prefetch" href="/assets/js/86.41850272.js"><link rel="prefetch" href="/assets/js/87.1cdc6df9.js"><link rel="prefetch" href="/assets/js/88.01bf3461.js"><link rel="prefetch" href="/assets/js/89.17c69819.js"><link rel="prefetch" href="/assets/js/9.3813842d.js"><link rel="prefetch" href="/assets/js/90.f6ae7e35.js"><link rel="prefetch" href="/assets/js/91.507bc284.js"><link rel="prefetch" href="/assets/js/92.90551782.js"><link rel="prefetch" href="/assets/js/93.dc442d78.js"><link rel="prefetch" href="/assets/js/94.315f4e94.js"><link rel="prefetch" href="/assets/js/95.ccd6c6bf.js"><link rel="prefetch" href="/assets/js/96.0c6d89d0.js"><link rel="prefetch" href="/assets/js/97.1a9f10a9.js"><link rel="prefetch" href="/assets/js/98.43be3caa.js"><link rel="prefetch" href="/assets/js/99.54c8207b.js">
    <link rel="stylesheet" href="/assets/css/0.styles.0dbae9ec.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><!----> <span class="site-name">whoway</span></a> <div class="links" style="max-width:nullpx;"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">🎓Coding</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/00.Coding/TheBeautyOfProgramming/" class="nav-link">🔖编程之美题解</a></li><li class="dropdown-item"><!----> <a href="/00.Coding/CodeWarehouse/" class="nav-link">🔖代码意识流</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">🚀语言</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/01.Language/Overview/" class="nav-link">🔖概述</a></li><li class="dropdown-item"><!----> <a href="/01.Language/C/" class="nav-link">⭐️C</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Cpp/" class="nav-link">🚀C++</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Java/" class="nav-link">☕️Java</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Python/" class="nav-link">🧩Python3</a></li></ul></div></div><div class="nav-item"><a href="/02.Hardware/" class="nav-link">✔️硬件基础</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">⭐️软件基础</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/03.Software/01.DataStructureAndAlgorithm/" class="nav-link">🐾数据结构和算法</a></li><li class="dropdown-item"><!----> <a href="/03.Software/02.OS/" class="nav-link">💻操作系统</a></li><li class="dropdown-item"><!----> <a href="/03.Software/03.Net/" class="nav-link">☁️计算机网络</a></li><li class="dropdown-item"><!----> <a href="/03.Software/04.SE/" class="nav-link">✅软件工程</a></li></ul></div></div><div class="nav-item"><a href="/04.Database/" class="nav-link">🎨数据库</a></div><div class="nav-item"><a href="/05.Engineer/" class="nav-link router-link-active">🔖学术/工程</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">⚙️工具</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/06.Tools/01.employment/" class="nav-link">🔖求职</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/02.efficiency/" class="nav-link">🚀效能</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/03.windows/" class="nav-link">⚙️Windows</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/04.design/" class="nav-link">🧩设计</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/05.linux/" class="nav-link">🐉Linux</a></li></ul></div></div><div class="nav-item"><a href="https://github.com/whoway" target="_blank" rel="noopener noreferrer" class="nav-link external">
  GitHub
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar"><nav class="nav-links"><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">🎓Coding</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/00.Coding/TheBeautyOfProgramming/" class="nav-link">🔖编程之美题解</a></li><li class="dropdown-item"><!----> <a href="/00.Coding/CodeWarehouse/" class="nav-link">🔖代码意识流</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">🚀语言</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/01.Language/Overview/" class="nav-link">🔖概述</a></li><li class="dropdown-item"><!----> <a href="/01.Language/C/" class="nav-link">⭐️C</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Cpp/" class="nav-link">🚀C++</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Java/" class="nav-link">☕️Java</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Python/" class="nav-link">🧩Python3</a></li></ul></div></div><div class="nav-item"><a href="/02.Hardware/" class="nav-link">✔️硬件基础</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">⭐️软件基础</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/03.Software/01.DataStructureAndAlgorithm/" class="nav-link">🐾数据结构和算法</a></li><li class="dropdown-item"><!----> <a href="/03.Software/02.OS/" class="nav-link">💻操作系统</a></li><li class="dropdown-item"><!----> <a href="/03.Software/03.Net/" class="nav-link">☁️计算机网络</a></li><li class="dropdown-item"><!----> <a href="/03.Software/04.SE/" class="nav-link">✅软件工程</a></li></ul></div></div><div class="nav-item"><a href="/04.Database/" class="nav-link">🎨数据库</a></div><div class="nav-item"><a href="/05.Engineer/" class="nav-link router-link-active">🔖学术/工程</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">⚙️工具</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/06.Tools/01.employment/" class="nav-link">🔖求职</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/02.efficiency/" class="nav-link">🚀效能</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/03.windows/" class="nav-link">⚙️Windows</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/04.design/" class="nav-link">🧩设计</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/05.linux/" class="nav-link">🐉Linux</a></li></ul></div></div><div class="nav-item"><a href="https://github.com/whoway" target="_blank" rel="noopener noreferrer" class="nav-link external">
  GitHub
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <!----></nav>  <ul class="sidebar-links"><li><div class="sidebar-group first"><p class="sidebar-heading open"><span>Vim常用命令</span> <!----></p> <ul class="sidebar-group-items"><li><a href="/05.Engineer/tool/1.Vim%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4.html#_1-vim三种模式" class="sidebar-link">1.Vim三种模式</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/05.Engineer/tool/1.Vim%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4.html#_1-1-命令模式" class="sidebar-link">1.1.命令模式</a></li><li class="sidebar-sub-header"><a href="/05.Engineer/tool/1.Vim%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4.html#_1-2-输入模式" class="sidebar-link">1.2.输入模式</a></li><li class="sidebar-sub-header"><a href="/05.Engineer/tool/1.Vim%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4.html#_1-3-末行模式" class="sidebar-link">1.3.末行模式</a></li></ul></li><li><a href="/05.Engineer/tool/1.Vim%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4.html#_2-常见场景✅" class="sidebar-link">2.常见场景✅</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/05.Engineer/tool/1.Vim%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4.html#_2-1-vim在同一个窗口中同时编辑多个文件" class="sidebar-link">2.1.vim在同一个窗口中同时编辑多个文件</a></li><li class="sidebar-sub-header"><a href="/05.Engineer/tool/1.Vim%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4.html#_2-2-vim-永久显示行号" class="sidebar-link">2.2.vim 永久显示行号</a></li><li class="sidebar-sub-header"><a href="/05.Engineer/tool/1.Vim%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4.html#_2-3-在vim打开的文本中查找字符串「类似windows的ctrl-f」" class="sidebar-link">2.3.在vim打开的文本中查找字符串「类似Windows的Ctrl+F」</a></li><li class="sidebar-sub-header"><a href="/05.Engineer/tool/1.Vim%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4.html#_2-4-vim查找字符-高亮显示" class="sidebar-link">2.4.vim查找字符&quot;高亮显示&quot;</a></li></ul></li></ul></div></li></ul> </div> <div class="page"> <div class="content"><h1 id="vim常用命令"><a href="#vim常用命令" class="header-anchor">#</a> Vim常用命令</h1> <div class="language-txt line-numbers-mode"><pre class="language-text"><code>&lt;font style=&quot;background:yellow&quot;&gt;
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h2 id="_1-vim三种模式"><a href="#_1-vim三种模式" class="header-anchor">#</a> 1.Vim三种模式</h2> <p>Vim编辑器中设置了三种模式一命令模式、末行模式和编辑模式
<strong>每种模式分别又支持多种不同的命令快捷键</strong></p> <p>我们先弄清这三种模式的操作区别以及模式之间的切换方法</p> <ul><li><strong>命令模式</strong>：控制光标移动，可对文本进行复制、粘贴、删除和查找等工作。</li> <li>输入模式：正常的文本录入。</li> <li><strong>末行模式</strong>：保存或退出文档，以及设置编辑环境。</li></ul> <p><img src="https://cdn.jsdelivr.net/gh/HACV/picture/img/2020_06_22_Vim_01.png" alt="2020_06_22_Vim_01"></p> <p>说明：
<code>vim 文件名</code> 则进入了vim的命令模式</p> <ul><li>1）在每次运行Vim编辑器时，<strong>默认进入</strong>命令模式</li> <li>2）此外，每次在编写完文档后需要先返回命令模式，然后再进人末行模式，执行文档.的保存或退出操作。</li> <li><strong>在Vim中，无法直接从输人模式切换到末行模式</strong></li></ul> <p><font style="background:pink;">命令模式进入输入模式</font>：</p> <ul><li><p>i取自insert插入</p> <ul><li><code>i</code> 光标处<strong>前一个字符</strong>编辑</li> <li><code>I</code> 大写的 i，光标所处<strong>行首</strong>编辑</li></ul></li> <li><p><strong>a取append</strong>追加，（我记得在Python中有用过这个函数，然后似乎C++11中也有？）</p> <ul><li><code>a</code> 光标处<strong>后一个字符</strong>编辑</li> <li><code>A</code> 光标所处<strong>行尾</strong>编辑</li></ul></li> <li><p>暂时没想到</p> <ul><li><code>o</code> 光标处<strong>向下</strong>新建一行编辑</li> <li><code>O</code> 大写的 o，光标处<strong>向上</strong>新建一行编辑</li></ul></li></ul> <h3 id="_1-1-命令模式"><a href="#_1-1-命令模式" class="header-anchor">#</a> 1.1.命令模式</h3> <p>命令模式：控制光标移动，可对文本进行复制、粘贴、删除和查找等工作</p> <p><strong>剪切</strong>类（可以用作删除）（但是<strong>d却是delete删除，首字母</strong>）</p> <ul><li><code>dd</code>剪切(删除)<strong>光标所在整行</strong></li> <li><code>5dd</code>删除(剪切)从光标处开始的5行</li></ul> <p><strong>复制</strong>类（暂时用<strong>copy的末尾y记忆</strong>）</p> <ul><li><code>yy</code>复制<strong>光标所在整行</strong></li> <li><code>5yy</code>复制从光标处开始的5行</li></ul> <p><strong>粘贴</strong>（<strong>p是paste</strong>粘贴，首字符）</p> <ul><li><code>p</code>将之前剪切(<code>dd</code>)或复制(<code>yy</code>)过的数据粘贴到光标后面</li></ul> <p><font style="background:yellow;">撤销</font>（<strong>u是unsay</strong>收回，撤回，首字母）</p> <ul><li><code>u</code>撤销上一步的操作</li> <li><strong>Ctrl+R (组合键</strong>) 反撤销（后悔撤销）</li></ul> <p><strong>单个字符</strong>修改</p> <ul><li><code>X</code>删除光标所处的字符：X（和Windows下Ctrl+X有点类似了，但是只是删除）</li> <li>按<code>R</code>后输入新的字符替换光标所处的字符</li></ul> <p><strong>字符串匹配</strong>后续的命令</p> <ul><li><code>n</code>显示搜索命令定位到的下一个<strong>字符串</strong></li> <li><code>N</code>显示搜索命令定位到的上一个<strong>字符串</strong></li></ul> <h3 id="_1-2-输入模式"><a href="#_1-2-输入模式" class="header-anchor">#</a> 1.2.输入模式</h3> <p>输人模式：正常的文本录入。</p> <h3 id="_1-3-末行模式"><a href="#_1-3-末行模式" class="header-anchor">#</a> 1.3.末行模式</h3> <p>末行模式：保存或退出文档，以及设置编辑环境</p> <ul><li>末行模式的命令都写在你用<code>:</code>进去末行模式后面
<ul><li>（我有其他看法，我觉得“字符串匹配”的时候，是<font style="background:yellow;">通过<code>/</code>或者<code>?</code>进入</font>的末行模式）</li> <li>总的来说格式：<code>:命令</code>执行该命令</li></ul></li></ul> <p><strong>下面的在展示的时候都省略了<code>:</code></strong></p> <ul><li><code>整数</code>跳转到这个整数的那一行</li> <li><code>w</code> 保存</li> <li><code>q</code> 退出（quit）</li> <li><code>q!</code>强制退出（放弃对文档的修改内容）</li> <li><code>wq!</code>强制保存退出</li></ul> <blockquote><p>看代码常用</p></blockquote> <ul><li><code>set nu</code>显示行号，nu—num</li> <li><code>set nonu</code>显示行号</li></ul> <blockquote><p>查找和替换</p></blockquote> <ul><li><p>查找</p> <ul><li><p><code>/字符串</code> 在文本中<font style="background:yellow;"><strong>从上至下</strong></font>搜索该字符串</p></li> <li><p><code>?字符串</code> 在文本中<strong>从下至上</strong>搜索该字符串</p></li> <li><p>在查找模式中加入<code>\c</code>「小写的c」表示<font style="background:yellow;">大小写不敏感查找</font>，<code>\C</code>表示大小写敏感查找。例如：</p> <ul><li><font style="background:pink;">记忆法：c意思是：case</font></li></ul> <div class="language- line-numbers-mode"><pre class="language-text"><code>/foo\c
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div></li></ul></li> <li><p>替换「<font style="background:yellow;">substitute ，n.代替者，v.替代</font>」</p> <ul><li><code>:s/one/two</code>将<strong>当前光标所在行</strong>的第一个 one替换成two</li> <li><code>:s/one/two/g</code>将当<strong>前光标所在行</strong>的<strong>所有</strong>one替换成two「<font style="background:yellow;">global，adj.全局的，完整的；全体的</font>」</li> <li><code>:%s/one/two/g 8s/one/two/g</code>将<strong>全文</strong>中的<font style="background:yellow;">所有</font>one替换成two</li></ul></li> <li><p>vim设置<strong>查找字符</strong>&quot;<font style="background:yellow;">高亮显示</font>&quot;及取消</p> <ul><li><code>set hlsearch</code></li> <li>high Light，高亮</li> <li>取消是<code>set nohlsearch</code></li></ul></li> <li><p>gg 移动到这个档案的<strong>第一行</strong>，相当于 1G 啊！ (常用)</p> <ul><li>G『也就是shift+g』移动到这个档案的<strong>最后一行</strong>(常用)</li></ul></li></ul> <blockquote><p>参考资料：<a href="https://www.runoob.com/linux/linux-vim.html" target="_blank" rel="noopener noreferrer">https://www.runoob.com/linux/linux-vim.html<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></p></blockquote> <h2 id="_2-常见场景✅"><a href="#_2-常见场景✅" class="header-anchor">#</a> 2.常见场景✅</h2> <h3 id="_2-1-vim在同一个窗口中同时编辑多个文件"><a href="#_2-1-vim在同一个窗口中同时编辑多个文件" class="header-anchor">#</a> 2.1.vim在同一个窗口中同时编辑多个文件</h3> <ul><li>我的场景：组会，需要展示2份汇编的对比</li> <li>「比如23.8寸的电脑，展示代码对比」因为可以承载代码放2边了</li></ul> <h4 id="_2-1-1-如果在终端中开没有打开vim，可以："><a href="#_2-1-1-如果在终端中开没有打开vim，可以：" class="header-anchor">#</a> 2.1.1.如果在终端中开没有打开vim，可以：</h4> <p>横向分割显示：</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>$ <span class="token function">vim</span> -o filename1 filename2 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>纵向分割显示：（左右）</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>$ <span class="token function">vim</span> -O filename1 filename2
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li><font style="background:pink;">记忆法：o意思是：open</font></li></ul> <h4 id="_2-1-2-如果已经用vim打开了一个文件，想要在窗口中同时再打开另一个文件："><a href="#_2-1-2-如果已经用vim打开了一个文件，想要在窗口中同时再打开另一个文件：" class="header-anchor">#</a> 2.1.2.如果已经用vim打开了一个文件，想要在窗口中同时再打开另一个文件：</h4> <ul><li>==vertical，adj.垂直的；竖的==，n.垂直线；垂直面</li></ul> <p><strong>纵向分割</strong>显示：（就是左边和右边）</p> <ul><li>去“末行模式”输入</li></ul> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>:vs filename
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>纵向分割显示：</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>:sp filename
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>其中，vs可以用vsplit替换，sp可以用==split替换==。</p> <p>如果finename不存在，则会新建该文件并打开。</p> <h4 id="_2-1-3-关闭窗口"><a href="#_2-1-3-关闭窗口" class="header-anchor">#</a> 2.1.3.关闭窗口</h4> <p>关闭<strong>光标所在</strong>的窗口：</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>:q 或 :close
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>关闭<strong>除</strong>光标所在的窗口之外的其他窗口：</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>:only
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>关闭所有窗口：</strong></p> <ul><li>意思是quit all</li></ul> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>:qa
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h4 id="_2-1-4-切换窗口"><a href="#_2-1-4-切换窗口" class="header-anchor">#</a> 2.1.4.切换窗口</h4> <p><strong>打开了多个窗口，需要在窗口之间切换时：</strong></p> <p><strong>ctrl + w w</strong></p> <ul><li>即==按住ctrl键，再按两下w键==</li></ul> <p>或者ctrl + w &lt;h|j|k|l&gt;</p> <p>即按住ctrl键，按一次w键，再按一次表示方向的h或j或k或l，则光标会切换到当前窗口的 左｜下｜上｜右 侧的窗口</p> <h3 id="_2-2-vim-永久显示行号"><a href="#_2-2-vim-永久显示行号" class="header-anchor">#</a> 2.2.vim 永久显示行号</h3> <p>如果想让vim永久显示行号，则需要修改vim配置文件vimrc。如果没有此文件可以创建一个。在启动vim时，当前用户根目录下的vimrc文件会被自动读取，因此一般在当前用户的根目录下创建vimrc文件，即使用下面的命令：</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token function">vim</span> ~/.vimrc
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>然后在最好在最后加上set nu</p> <p>但是，我的~/下和/home/huwei下都没有</p> <p>所以，我vim /home/huwei/.vimrc里面写了这个，新建了，也有效果</p> <ul><li>从windows下用习惯了devC++和VS等
其实，还是要显示行数的好，不然都不好调试代码</li></ul> <h4 id="_2-永久显示行号"><a href="#_2-永久显示行号" class="header-anchor">#</a> 2.永久显示行号</h4> <p>众所周知要想要Linux下的设置永久生效，要写入磁盘才好</p> <p>而Linux下一切都是文件，也就是说，要写入相关文件</p> <p>首先去</p> <div class="language-sh line-numbers-mode"><pre class="language-text"><code>cd /
cd etc/
[root@iZwz9ivqsnyj6hi71t3pamZ etc]# pwd
/etc
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><div class="language-sh line-numbers-mode"><pre class="language-text"><code>[root@iZwz9ivqsnyj6hi71t3pamZ etc]# ls | grep 'vim'
vimrc
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><div class="language-sh line-numbers-mode"><pre class="language-text"><code>vim vimrc
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>如果想让vim永久显示行号，则需要修改vim配置文件vimrc。如果没有此文件可以创建一个。在启动vim时，当前用户根目录下的vimrc文件会被自动读取，因此一般在当前用户的根目录下创建vimrc文件，即使用下面的命令：</p> <p>vimrc文件中最后一行输入：set number ，然后保存退出。再次用vim打开文件时，就会显示行号了。</p> <div class="language-sh line-numbers-mode"><pre class="language-text"><code>let &amp;guicursor = &amp;guicursor . &quot;,a:blinkon0&quot;
&quot; 2020-09-11  设置命令，全局set number,上面是本来就有的
set number
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h3 id="_2-3-在vim打开的文本中查找字符串「类似windows的ctrl-f」"><a href="#_2-3-在vim打开的文本中查找字符串「类似windows的ctrl-f」" class="header-anchor">#</a> 2.3.在vim打开的文本中查找字符串「类似Windows的Ctrl+F」</h3> <ul><li>在normal模式下按下<code>/</code>即可进入查找模式
<ul><li>「==就像，我们输入<code>:</code>会进入其他模式一样==」，输入要查找的字符串并按下回车。</li> <li>Vim会跳转到第一个匹配。按下<code>n</code>查找下一个，按下<code>N</code>查找上一个。「==因为这个时候的<code>n</code>的意义不再是下一行，而是匹配的下一个==」</li></ul></li></ul> <h3 id="_2-4-vim查找字符-高亮显示"><a href="#_2-4-vim查找字符-高亮显示" class="header-anchor">#</a> 2.4.vim查找字符&quot;高亮显示&quot;</h3> <blockquote><p>方便在公司or组会的时候展示，我的具体<strong>代码排查</strong></p></blockquote> <ul><li>vi打开用户根目录， vi ~/.vimrc(如果没有会自动创建这一目录)，这一目录是当前登录用户的vim设定，设置行号之类的操作也是在这里指定。</li> <li>输入一行 <code>set hlsearch</code></li> <li><code>:wq</code>保存退出，即设置完成，此时用vim打开任意文档搜索字符串都可显示高亮。</li></ul> <p>还能，修改高亮的颜色</p> <ul><li><a href="https://harttle.land/2016/08/08/vim-search-in-file.html" target="_blank" rel="noopener noreferrer">参考资料<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul></div> <div class="page-edit"><!----> <!----></div> <!----> </div> <!----></div></div>
    <script src="/assets/js/app.c70e21ad.js" defer></script><script src="/assets/js/108.a2fecadc.js" defer></script>
  </body>
</html>
